package com.qrcode.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.qrcode.utils.QRCodeUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.Response;

@RestController
@Api(tags = "生成二维码")
public class QRCodeController {

	@GetMapping("/encode/{text}/{logoPath}/{destPath}")
	@ApiOperation("将生成的二维码发到指定的路径中")
	public String encoder(@PathVariable @ApiParam("二维码信息") String text,@PathVariable @ApiParam("附加logo地址") String logoPath,@PathVariable @ApiParam("二维码生成的路径") String destPath) {
		try {
			QRCodeUtil.encode(text, logoPath, destPath, true);
			return destPath;
		} catch (Exception e) {
			e.printStackTrace();
			return "生成二维码失败!";
		}
	}
	
	
	@GetMapping("/encode/{text}")
	@ApiOperation("生成的二维码")
	public void encoder(@PathVariable @ApiParam("二维码信息") String text,HttpServletResponse res) {
		try {
			QRCodeUtil.encode(text, res.getOutputStream());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
